package net.sourceforge.krama.tag.widget;

import java.util.ArrayList;
import java.util.List;

import net.sourceforge.krama.css.CSSImage;
import net.sourceforge.krama.css.CSSLink;
import net.sourceforge.krama.html.child.HTMLImage;
import net.sourceforge.krama.html.child.HTMLLink;
import net.sourceforge.krama.listener.TEventListener;
import net.sourceforge.krama.listener.TMouseListener;


public class TImage extends AbstractT {

	private String src;
	private String title;
	private String name;
	private String parentName;
	private String html;

	private CSSImage cssImage = new CSSImage();
	private HTMLImage htmlImage = new HTMLImage();

	private List<TEventListener> listenerList = new ArrayList<TEventListener>();
	
	private String fonction;
	
	public TImage(String src){
		this.src = src;
		htmlImage.setSrc(this.src);
	}
	
	@Override
	public void draw() {
		// TODO Auto-generated method stub

		this.html = htmlImage.starDraw();
		this.html += htmlImage.endDraw();
	}

	@Override
	public void setParentName(String parentName) {
		// TODO Auto-generated method stub
		this.parentName = parentName;
	}

	public void setName(String name) {
		if (name != null) {
			this.name = "krama-" + name;
			htmlImage.setName(this.name);
		}
	}
	
	@Override
	public String getHtml() {
		// TODO Auto-generated method stub
		return html;
	}

	public void addTMouseListener(TMouseListener mouseListener, String id)
			throws IllegalArgumentException {

		listenerList.add(mouseListener);
		fonction = mouseListener.onClick();
		fonction += ", 'krama-" + id + "'";
		htmlImage.addClick(fonction);
	}

	public String getCSS() {
		if (name != null) {
			return cssImage.getCSS("."+parentName + " ." + name);
		} else
			return "";
	}

	public void setSrc(String src) {
		this.src = src;
		htmlImage.setSrc(this.src);
	}

	public void setTitle(String title) {
		this.title = title;
		htmlImage.setTitle(this.title);
	}
}
